/*
 * VacuumValueFrame.java
 *
 * Created on Oct 30, 2011, 12:07:42 PM
 */

package gui;
/**
 *
 * @author suzann
 */

/*
 * Import Java Classes
 */

import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferStrategy;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;

import java.util.List;
import java.util.*;
/*
 * Import own classes
 */
import util.*;
import db.DatabaseManager;
import db.entity.Pressurevalue;
import db.entity.TaperValue;

public class VacuumValueFrame extends JFrame {

    /** Creates new form VacuumValueFrame */
    public VacuumValueFrame() {
        //initialise the gui components
        initComponents();
        //set the default value for vacuum values
        setDefaultValue();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jbtEdit = new javax.swing.JButton();
        jbtSave = new javax.swing.JButton();
        jbtCancel = new javax.swing.JButton();
        jlbStation = new javax.swing.JLabel();
        jlbLeftVac = new javax.swing.JLabel();
        jlbRightVac = new javax.swing.JLabel();
        jlb1 = new javax.swing.JLabel();
        jtxL1 = new javax.swing.JTextField();
        jtxL2 = new javax.swing.JTextField();
        jlb2 = new javax.swing.JLabel();
        jtxR1 = new javax.swing.JTextField();
        jtxR2 = new javax.swing.JTextField();
        jlb3 = new javax.swing.JLabel();
        jtxL3 = new javax.swing.JTextField();
        jtxR3 = new javax.swing.JTextField();
        jlb4 = new javax.swing.JLabel();
        jtxL4 = new javax.swing.JTextField();
        jtxR4 = new javax.swing.JTextField();
        jlb5 = new javax.swing.JLabel();
        jtxL5 = new javax.swing.JTextField();
        jtxR5 = new javax.swing.JTextField();
        jlb6 = new javax.swing.JLabel();
        jtxL6 = new javax.swing.JTextField();
        jtxR6 = new javax.swing.JTextField();
        jlb7 = new javax.swing.JLabel();
        jtxL7 = new javax.swing.JTextField();
        jtxR7 = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jbtEdit.setText("Edit");
        jbtEdit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtEditActionPerformed(evt);
            }
        });

        jbtSave.setText("Save");
        jbtSave.setEnabled(false);
        jbtSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtSaveActionPerformed(evt);
            }
        });

        jbtCancel.setText("Cancel");
        jbtCancel.setEnabled(false);
        jbtCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtCancelActionPerformed(evt);
            }
        });

        jlbStation.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jlbStation.setText("Station");

        jlbLeftVac.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jlbLeftVac.setText("Left Vacuum(Inches Hg)");

        jlbRightVac.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jlbRightVac.setText("Right Vacuum(Inches Hg)");

        jlb1.setText("01");

        jtxL1.setEditable(false);

        jtxL2.setEditable(false);

        jlb2.setText("02");

        jtxR1.setEditable(false);
        jtxR1.setHorizontalAlignment(javax.swing.JTextField.LEFT);

        jtxR2.setEditable(false);
        jtxR2.setHorizontalAlignment(javax.swing.JTextField.LEFT);

        jlb3.setText("03");

        jtxL3.setEditable(false);

        jtxR3.setEditable(false);
        jtxR3.setHorizontalAlignment(javax.swing.JTextField.LEFT);

        jlb4.setText("04");

        jtxL4.setEditable(false);

        jtxR4.setEditable(false);
        jtxR4.setHorizontalAlignment(javax.swing.JTextField.LEFT);

        jlb5.setText("05");

        jtxL5.setEditable(false);

        jtxR5.setEditable(false);
        jtxR5.setHorizontalAlignment(javax.swing.JTextField.LEFT);

        jlb6.setText("06");

        jtxL6.setEditable(false);

        jtxR6.setEditable(false);
        jtxR6.setHorizontalAlignment(javax.swing.JTextField.LEFT);

        jlb7.setText("07");

        jtxL7.setEditable(false);

        jtxR7.setEditable(false);
        jtxR7.setHorizontalAlignment(javax.swing.JTextField.LEFT);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jlbStation)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jlbLeftVac))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jlb1)
                                    .addComponent(jlb2))
                                .addGap(28, 28, 28)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jtxL1)
                                    .addComponent(jtxL2, javax.swing.GroupLayout.DEFAULT_SIZE, 115, Short.MAX_VALUE)
                                    .addComponent(jtxL3, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jtxL4, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jtxL5, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jtxL6, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jtxL7, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addComponent(jlb3)
                            .addComponent(jlb4)
                            .addComponent(jlb5)
                            .addComponent(jlb6)
                            .addComponent(jlb7))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jtxR7, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jtxR6, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jtxR5, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jtxR4, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jtxR3, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jtxR2, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jtxR1, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jlbRightVac)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jbtEdit)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbtSave)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbtCancel)))
                .addContainerGap(19, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlbStation)
                    .addComponent(jlbLeftVac)
                    .addComponent(jlbRightVac))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlb1)
                    .addComponent(jtxL1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtxR1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtxL2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlb2)
                    .addComponent(jtxR2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlb3)
                    .addComponent(jtxL3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtxR3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlb4)
                    .addComponent(jtxL4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtxR4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlb5)
                    .addComponent(jtxL5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtxR5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlb6)
                    .addComponent(jtxL6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtxR6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlb7)
                    .addComponent(jtxL7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtxR7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbtEdit)
                    .addComponent(jbtSave)
                    .addComponent(jbtCancel))
                .addContainerGap(97, Short.MAX_VALUE))
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-378)/2, (screenSize.height-388)/2, 378, 388);
    }// </editor-fold>                        

    private void jbtSaveActionPerformed(java.awt.event.ActionEvent evt) {     
        saveVacuumValue();
    }                                       

    private void jbtCancelActionPerformed(java.awt.event.ActionEvent evt) {                                          
    	// restore previous value 
    	// set all the text fields and buttons to become unedittable
        resetVacuumValue();
        toggleTextAndButtons(false);        
    }                                         

    private void jbtEditActionPerformed(java.awt.event.ActionEvent evt) {    
        editVacuumValue();
    }                                       

    
     /****************************************************************************
     * INTERNAL OPERATIONS : THE PRIVATE METHODS
     ****************************************************************************/
    /**
     * Retrieve the default value for each textfield.
     * 	The display value are previously entered value stored in database
     */
    private void setDefaultValue()
    {
    	dm = new DatabaseManager();
    	taperLS = dm.listTaperValue();
    	String stationID, leftRightIND;
    	int stationNo;
    	Double vacVal;
    	
    	for(TaperValue taperObj : taperLS)
    	{
    		stationID = taperObj.getTaperID();
    		vacVal = taperObj.getTaperValue();
    		leftRightIND = stationID.substring(0,1);
    		stationNo = Integer.parseInt(stationID.substring(1));
    		if(leftRightIND.equals("L"))
    		{
    			switch(stationNo)
    			{
    			case 1: jtxL1.setText(vacVal.toString()); break;
    			case 2: jtxL2.setText(vacVal.toString()); break;
    			case 3: jtxL3.setText(vacVal.toString()); break;
    			case 4: jtxL4.setText(vacVal.toString()); break;
    			case 5: jtxL5.setText(vacVal.toString()); break;
    			case 6: jtxL6.setText(vacVal.toString()); break;
    			case 7: jtxL7.setText(vacVal.toString()); break;
    			}
    			vacVal_L[stationNo-1] = vacVal;
    		}
    		else
    		{
    			switch(stationNo)
    			{
    			case 1: jtxR1.setText(vacVal.toString()); break;
    			case 2: jtxR2.setText(vacVal.toString()); break;
    			case 3: jtxR3.setText(vacVal.toString()); break;
    			case 4: jtxR4.setText(vacVal.toString()); break;
    			case 5: jtxR5.setText(vacVal.toString()); break;
    			case 6: jtxR6.setText(vacVal.toString()); break;
    			case 7: jtxR7.setText(vacVal.toString()); break;
    			}
    			vacVal_R[stationNo-1] = vacVal;
    		}
    	}
    }
    
    /**
     * Authenticate user before letting user edit the fields.
     * After authentication, enable the fields to let them editable.
     */
    private void editVacuumValue()
    {
        // When user trying to Edit Vacuum Value, authenticate the user first.
        // If Autehnticated, save the value, else prompt to enter the user again
        String username = null;
        boolean isEdit = false;
        do
        {
            username = Authentication.authenticateUser();
            if(username.equals("Invalid"))
            {
                JOptionPane.showMessageDialog(this, "Your username is invalid.\nPlease enter your username again.", "Authentication Failure", JOptionPane.WARNING_MESSAGE);
                System.out.println("Authentication failure attempted."); //Can be included into activity log later.
                continue;
            }
            else if (username.equals("Exit"))
            {
                System.out.println("Edit vacuum values action terminated."); //Can be included into activity log later.
                break;
            }
            else
            {
                if (username != null)
                {
                    isEdit = true;
                    userID = username;
                    //After Authentication, set all the fields to edittable.
                    toggleTextAndButtons(true);
                }
            }
        }while(isEdit == false);
    }
        
    /**
     * When user select Save button, then they will be updated to the database.
     */
    private void saveVacuumValue()
    {
        //update the values inside taperLS, then pass it back to DatabaseManager
    	String stationID, leftRightIND;
    	int stationNo;
        
        //get all the inputs and validate them
        Container c = this.getContentPane();
        Component[] comps = c.getComponents();
        ArrayList<Component> compList = new ArrayList <Component>();
        
        //looping textfields for validation
        for (Component comp : comps)
        {
            if (comp instanceof JTextField)
            {
                compList.add(comp);
            }
        }
        
        //validate the text fields
        boolean isRange = Validator.validateRange(compList, PropertiesLoader.getVacuumLowerLimit(), PropertiesLoader.getVacuumUpperLimit());
        boolean isBlank = Validator.validateBlank(compList);

        String activityLog_action = "Update Vacuum Value ";
        ArrayList<TaperValue> changeList = new ArrayList<TaperValue>();
        
        if ( isRange == true && isBlank == false )
        {
            //save into db if validated
            for(TaperValue taperObj : taperLS)
            {
                stationID = taperObj.getTaperID();
                leftRightIND = stationID.substring(0,1);
                stationNo = Integer.parseInt(stationID.substring(1));
                double taperValue = 0;
                boolean changed = false;
                
                if(leftRightIND.equals("L"))
                {
                        switch(stationNo)
                        {
                        case 1: taperValue = Double.parseDouble(jtxL1.getText());break;
                        case 2: taperValue = Double.parseDouble(jtxL2.getText());break;
                        case 3: taperValue = Double.parseDouble(jtxL3.getText());break;
                        case 4: taperValue = Double.parseDouble(jtxL4.getText());break;
                        case 5: taperValue = Double.parseDouble(jtxL5.getText());break;
                        case 6: taperValue = Double.parseDouble(jtxL6.getText());break;
                        case 7: taperValue = Double.parseDouble(jtxL7.getText());break;
                        }
                        if(taperValue != vacVal_L[stationNo-1])
                        {
                        	changed = true;
                        	vacVal_L[stationNo-1] = taperValue;
                        }
                }
                else
                {
                        switch(stationNo)
                        {
                        case 1: taperValue = Double.parseDouble(jtxR1.getText());break;
                        case 2: taperValue = Double.parseDouble(jtxR2.getText());break;
                        case 3: taperValue = Double.parseDouble(jtxR3.getText());break;
                        case 4: taperValue = Double.parseDouble(jtxR4.getText());break;
                        case 5: taperValue = Double.parseDouble(jtxR5.getText());break;
                        case 6: taperValue = Double.parseDouble(jtxR6.getText());break;
                        case 7: taperValue = Double.parseDouble(jtxR7.getText());break;    

                        }
                        if(taperValue != vacVal_R[stationNo-1])
                        {
                        	changed = true;
                        	vacVal_R[stationNo-1] = taperValue;
                        }
                }
                if(changed)
                {
                	taperObj.setTaperValue(taperValue);
                	taperObj.setAdjustmentValue(taperValue);
                	taperObj.setPlcValue(taperValue);
                  	
                   	PLCSend.updatePLCTaper(leftRightIND, stationID.substring(1), taperValue);
                	changeList.add(taperObj);
                	activityLog_action += stationID+":"+taperValue+";";
                }
            }
            //Update the Pressure Values
            //Activity log
            //set the text fields and button to unedittable
            //Then retrieve the value from database again
            dm.updateTaperValue(changeList);
            
            Activity.log(activityLog_action, userID, "");
            
            toggleTextAndButtons(false);
            setDefaultValue();
            
            //Show the successful dialog message
            JOptionPane.showMessageDialog(null, "Vacuum Values successfully updated.", "Update Successfully", JOptionPane.PLAIN_MESSAGE);
        }
    }
    
    private void resetVacuumValue()
    {
    	jtxL1.setText(vacVal_L[0].toString());
    	jtxL2.setText(vacVal_L[1].toString());
    	jtxL3.setText(vacVal_L[2].toString());
    	jtxL4.setText(vacVal_L[3].toString());
    	jtxL5.setText(vacVal_L[4].toString());
    	jtxL6.setText(vacVal_L[5].toString());
    	jtxL7.setText(vacVal_L[6].toString());
    	jtxR1.setText(vacVal_R[0].toString());
    	jtxR2.setText(vacVal_R[1].toString());
    	jtxR3.setText(vacVal_R[2].toString());
    	jtxR4.setText(vacVal_R[3].toString());
    	jtxR5.setText(vacVal_R[4].toString());
    	jtxR6.setText(vacVal_R[5].toString());
    	jtxR7.setText(vacVal_R[6].toString());
    }
    
    /**
     * @param isEdittable 
     * Pass in a boolean value to determine the text fields and buttons availability
     */
    private void toggleTextAndButtons(boolean isEdittable)
    {
        //If user select 'save', the isEdittable should be false
        //else if user select 'edit', the isEdittable should be true
        jtxL1.setEditable(isEdittable);
        jtxL2.setEditable(isEdittable);
        jtxL3.setEditable(isEdittable);
        jtxL4.setEditable(isEdittable);
        jtxL5.setEditable(isEdittable);
        jtxL6.setEditable(isEdittable);
        jtxL7.setEditable(isEdittable);
        
        jtxR1.setEditable(isEdittable);
        jtxR2.setEditable(isEdittable);
        jtxR3.setEditable(isEdittable);
        jtxR4.setEditable(isEdittable);
        jtxR5.setEditable(isEdittable);
        jtxR6.setEditable(isEdittable);
        jtxR7.setEditable(isEdittable);
        
        //set the availability of button
        jbtSave.setEnabled(isEdittable);
        jbtCancel.setEnabled(isEdittable);
        jbtEdit.setEnabled(!isEdittable);
    }

    
    public void addNotify() {
        super.addNotify();
        // Buffer
        createBufferStrategy(2);           
        //BufferStrategy strategy = getBufferStrategy();
    }
    
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(VacuumValueFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(VacuumValueFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(VacuumValueFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(VacuumValueFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        try {
			PropertiesLoader.getInstance();
		} catch (Exception e) {
			e.printStackTrace();
		}
        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new VacuumValueFrame().setVisible(true);
            }
        });
    }
    
    
    /****************************************************************************
     * INTERNAL OPERATIONS : THE FRAME
     ****************************************************************************/
    
    /**
     * Prompts up a confirmation dialog to confirm the exit action.
     * Upon confirmation, dispose the frame.
     */
    private void onExit()
    {
        //dispose the frame
        this.dispose();
        resetVacuumValue();
        toggleTextAndButtons(false);
    }
    
    /**
     * This is a hack for user to click on the 'x' button on window
     */
    protected void processWindowEvent(WindowEvent we)
    {
            if(we.getID() == WindowEvent.WINDOW_CLOSING)
                    onExit();
    }
    
    /****************************************************************************
     *  THE VARIABLES
     ****************************************************************************/
    
    // Variables declaration - do not modify                     
    private javax.swing.JButton jbtCancel;
    private javax.swing.JButton jbtEdit;
    private javax.swing.JButton jbtSave;
    private javax.swing.JLabel jlb1;
    private javax.swing.JLabel jlb2;
    private javax.swing.JLabel jlb3;
    private javax.swing.JLabel jlb4;
    private javax.swing.JLabel jlb5;
    private javax.swing.JLabel jlb6;
    private javax.swing.JLabel jlb7;
    private javax.swing.JLabel jlbLeftVac;
    private javax.swing.JLabel jlbRightVac;
    private javax.swing.JLabel jlbStation;
    private javax.swing.JTextField jtxL1;
    private javax.swing.JTextField jtxL2;
    private javax.swing.JTextField jtxL3;
    private javax.swing.JTextField jtxL4;
    private javax.swing.JTextField jtxL5;
    private javax.swing.JTextField jtxL6;
    private javax.swing.JTextField jtxL7;
    private javax.swing.JTextField jtxR1;
    private javax.swing.JTextField jtxR2;
    private javax.swing.JTextField jtxR3;
    private javax.swing.JTextField jtxR4;
    private javax.swing.JTextField jtxR5;
    private javax.swing.JTextField jtxR6;
    private javax.swing.JTextField jtxR7;
    // End of variables declaration                   

    //Variables declaration
    private DatabaseManager dm;
    private List<TaperValue> taperLS;
    private Double vacVal_L [] = new Double[7];
    private Double vacVal_R [] = new Double[7];
    private String userID;
}
